package com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.repository.impl;

import com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.entity.CphDamageEntity;
import com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.entity.GstInformationEntity;
import com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.entity.RdInformationEntity;
import com.css.fxfzfxqh.modules.vulnerabilityData.cztDataMange.repository.DomeFacilitiesRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class DomeFacilitiesRepositoryImpl implements DomeFacilitiesRepository {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public void saveHpInformation(CphDamageEntity cph) {
        jdbcTemplate.update("insert into czt_project_historical_damage(cphd_id,seism_name,seism_time,magnitude,project_type,fortification,years,params,break_state,create_user,create_time,del_flag,update_time,geom)" +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",cph.getCphdId(),cph.getSeismName(),cph.getSeismTime(),cph.getMagnitude(),cph.getProjectType(),cph.getFortification(),cph.getYears(),
                cph.getParams(),cph.getBreakState(),cph.getCreateUser(),cph.getCreateTime(),cph.getDelFlag(),cph.getUpdateTime(),cph.getGeom());
    }

    @Override
    public Boolean saveRdInformation(RdInformationEntity rd) {
        String sql = "insert into czt_reservior(cr_id, cr_name, location, longitude, latitude, capacity, year, dam_length, dam_height, top_width, " +
                "structure_type, type, intensity, site, space, filling, dam_foundation, maintenance_status, create_user, create_time, update_user, " +
                "update_time, del_flag, extends1, extends2, extends3, extends4, extends5, extends6,  extends7, extends8, extends9, extends10, " +
                "attach_id, province, city, county, geom, upload_time) " +
                "values(:crId, :crName, :location, :longitude, :latitude, :capacity, :year, :damLength, :damHeight, " +
                ":topWidth, :structureType, :type, :intensity, :site, :space, :filling, :damFoundation, :maintenanceStatus, :createUser, " +
                ":createTime, :updateUser, :updateTime, :delFlag, :extends1, :extends2, :extends3, :extends4, :extends5, :extends6, " +
                ":extends7, :extends8, :extends9, :extends10, " +
                ":attachId, :province, :city, :county, ST_GeometryFromText(:geom,4490), :uploadTime)";
        SqlParameterSource source = new BeanPropertySqlParameterSource(rd);
        return namedParameterJdbcTemplate.update(sql, source)>0;
    }

    @Override
    public void saveGstInformation(GstInformationEntity gst) {
        jdbcTemplate.update("insert into czt_air_receiver(car_id,car_code,car_name,longitude,latitude,style,capacity,pressure,inner_diameter,height,thickness,weight,material,rail_length,rail_height,rail_thickness,base_type,material_type," +
                "elastic_modulus,yield_stress,permissible_stress,site,liquefaction6,liquefaction7,liquefactio8,liquefaction9,seismic_subsidence6,seismic_subsidence7,seismic_subsidence8,seismic_subsidence9," +
                "year,intensity,create_user,create_time,del_flag,update_time,geom)values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",gst.getCarId(),gst.getCarCode(),gst.getCarName(),gst.getLongitude(),gst.getLatitude(),gst.getStyle(),gst.getCapacity(),gst.getPressure(),gst.getInnerDiameter(),
                gst.getHeight(),gst.getThickness(),gst.getWeight(),gst.getMaterial(),gst.getRailLength(),gst.getRailHeight(),gst.getRailThickness(),gst.getBaseType(),gst.getMaterialType(),
                gst.getElasticModulus(),gst.getYieldStress(),gst.getPermissibleStress(),gst.getSite(),gst.getLiquefaction6(),gst.getLiquefaction7(),gst.getLiquefaction8(),gst.getLiquefaction9(),
                gst.getSeismicSubsidence6(),gst.getSeismicSubsidence7(),gst.getSeismicSubsidence8(),gst.getSeismicSubsidence9(),gst.getYear(),gst.getIntensity(),gst.getCreateUser(),gst.getCreateTime(),
                gst.getDelFlag(),gst.getUploadTime(),gst.getGeom());
    }

    @Override
    public int getProjectDataByProvince(String province) {

            return 0;

    }

    @Override
    public int getReserviorDataByProvince(String province) {
        try{
            String sql="select count(cr_id) from czt_reservior where del_flag= '0' and province= ?";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }

    @Override
    public int getMajorProjectDataByProvince(String province) {
        try{
            String sql="select count(cmp_id) from czt_major_project where del_flag= '0' and province= ? ";
            int count = jdbcTemplate.queryForObject(sql, Integer.class,province);
            return count;
        } catch (Exception e){
            return 0;
        }
    }


}
